﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using CoiffeurProject.Screens;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
using System.Windows.Media.Imaging;
using CoiffeurProject.Utils;
using System.Windows.Media;
using CoiffeurProject.DBMS.Entities;
using CoiffeurProject.DBMS.Tables;

namespace CoiffeurProject.UserControls
{
    internal class ScrollViewerEntry
    {
        Grid main_container;
        Image rollover;
        Image selected;
        Button button;
        Rectangle separator;

        bool isSelected = false;

        internal ScrollViewerEntry(Grid content, string img_uri, int width, int height)
        {
            main_container = new Grid()
            {
                Width = width,
                Height = height,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            
            main_container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(height - 3) });
            main_container.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            
            rollover = new Image()
            {
                Source = new BitmapImage(new Uri(img_uri)),
                Width = width,
                Height = height - 3,
                Opacity = 0.7,
                Visibility = Visibility.Hidden,
                Stretch = Stretch.Fill
            };

            main_container.Children.Add(rollover);

            selected = new Image()
            {
                Source = new BitmapImage(new Uri(img_uri)),
                Width = width,
                Height = height - 3,
                Opacity = 1,
                Visibility = Visibility.Hidden,
                Stretch = Stretch.Fill
            };

            main_container.Children.Add(selected);

            main_container.Children.Add(content);

            button = new Button()
            {
                Content = new Image()
                {
                    Source = new BitmapImage(new Uri(ImagesPath.Blank)),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Stretch = Stretch.Fill
                },
                Width = width - 20,
                Height = height - 10,
            };

            button.MouseEnter += new MouseEventHandler(button_MouseEnter);
            button.MouseLeave += new MouseEventHandler(button_MouseLeave);
            button.SetResourceReference(Button.StyleProperty, "NoChromeButton");

            main_container.Children.Add(button);

            separator = new Rectangle()
            {
                Width = width - 20,
                Height = 1,
                Opacity = 1,
                Fill = new SolidColorBrush(Colors.Gray)
            };

            Grid.SetRow(separator, 1);
            main_container.Children.Add(separator);
        }

        internal void AddClickHandlers(Action<object, RoutedEventArgs> clickHandler)
        {
            button.Click +=new RoutedEventHandler(clickHandler);
        }

        private void button_MouseLeave(object sender, MouseEventArgs e)
        {
            rollover.Visibility = Visibility.Hidden;
        }

        private void button_MouseEnter(object sender, MouseEventArgs e)
        {
            rollover.Visibility = Visibility.Visible;
        }

        internal void ToggleSelected()
        {
            selected.Visibility = isSelected ? Visibility.Hidden : Visibility.Visible;

            isSelected = !isSelected;
        }

        public Grid MainContainer
        {
            get { return main_container; }
        }

        public bool IsSelected
        {
            get { return isSelected; }
            set { isSelected = value; }
        }

        public Rectangle Separator
        {
            get { return separator; }
            set { separator = value; }
        }

        public Button Button
        {
            get { return button; }
            set { button = value; }
        }

        public Image Selected
        {
            get { return selected; }
            set { selected = value; }
        }

        public Image Rollover
        {
            get { return rollover; }
            set { rollover = value; }
        }
    }

    internal class ScrollViewerNotificationEntry
    {
        Grid main_container;
        Label notification_text;
        Rectangle separator;

        internal ScrollViewerNotificationEntry(String message)
        {
            main_container = new Grid()
            {
                Width = 345,
                Height = 36,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            main_container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(35) });
            main_container.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

            #region Labels

            notification_text = new Label()
            {
                Content = message.Length > 35 ? message.Substring(0, 33) + "..." : message,
                FontSize = 18,
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalContentAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(3, 0, 0, 0),
                Width = 340,
                Height = 35,
            };

            main_container.Children.Add(notification_text);

            #endregion

            separator = new Rectangle()
            {
                Width = 345,
                Height = 1,
                Opacity = 1,
                Fill = new SolidColorBrush(Colors.Gray)
            };

            Grid.SetRow(separator, 1);
            main_container.Children.Add(separator);
        }

        public Grid MainContainer
        {
            get { return main_container; }
        }
    }
}
